home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / AMOSList / AMOSLIST / text0106.txt < prev    next >
Encoding:
Text File  |  1998-04-01  |  1.7 KB  |  56 lines

  1.  
  2. > Hey again, 
  3. > I have a little question..
  4. > why does this cause me to get an "Out of stack space" Error and what can I
  5. > do to remedy it?
  6. > Thanx in advatz!!! :)
  7.  
  8.     This is a classic programing pit fall, every time you jump to
  9. one procedure from within another, all the data (variables) from the
  10. procedure you are leaving are tossed on the 'stack' basically they are
  11. stored in quick temporary memory so they can be recalled quickly when you
  12. return to the original procedure.
  13.  
  14. ex.
  15. Procedure FUN_TIMES
  16. x=100
  17. y=320
  18. ght=345
  19.  
  20. Proc GOOD_TIMES
  21.  
  22. End Proc
  23.  
  24.     Now when the program hops to GOOD_TIMES in that last line all the
  25. variables (x,y,ght) are thrown on the stack, and then recalled again
  26. whenever GOOD_TIMES returns.  Follow all that?
  27.     Wel the problem arises when you have too many nested or looped
  28. procedure calls, then too much data gets stuck on the stack and it fills
  29. up, giving you an out of stack erorr, so:
  30.  
  31. Procedure GOOD_TIMES
  32.  
  33. y=1002
  34. x=1232
  35.  
  36.  
  37. For I=1 to 50
  38. proc GOOD_TIMES
  39. Next I
  40.  
  41. End Proc
  42.  
  43. Will quickly use up the stack since each time GOOD_TIMES is called anew x
  44. and y are dumped on the stack not to be cleared until the new GOOD_TIMES
  45. returns. (which I actually think is never in this case)  So too many x's
  46. and y's build up on the stack (yup even though they all have the same
  47. value, since Amos doesn't know that) and you get an out of stack error. 
  48. Hpe that clears things up a bit, I deleted your bit of code before I could
  49. see where your stack error was but bottom line too many looped procedure
  50. calls or Gosubs (Gosub exhibits the exact same problem, this time because
  51. the old location (where to return to) is stored on the stack ) 
  52.  Well hope that wasn't too dense.  Let me know if you've anymore
  53. questions, and happy coding!
  54.  
  55.  
  56.